﻿Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.ComponentModel.Design.Serialization
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Globalization
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Windows.Forms
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Serialization

Namespace System.Workflow.ComponentModel.Design
    <ActivityDesignerTheme(GetType(CompositeDesignerTheme)), SRCategory("CompositeActivityDesigners", "System.Workflow.ComponentModel.Design.DesignerResources"), DesignerSerializer(GetType(CompositeActivityDesignerLayoutSerializer), GetType(WorkflowMarkupSerializer))> _
    Public MustInherit Class CompositeActivityDesigner
        Inherits ActivityDesigner
        ' Methods
        Protected Sub New()
        End Sub

        Public Overridable Function CanInsertActivities(ByVal insertLocation As HitTestInfo, ByVal activitiesToInsert As ReadOnlyCollection([Of] Activity)) As Boolean
            If (insertLocation Is Nothing) Then
                Throw New ArgumentNullException("insertLocation")
            End If
            If (activitiesToInsert Is Nothing) Then
                Throw New ArgumentNullException("activitiesToInsert")
            End If
            If Not TypeOf MyBase.Activity Is CompositeActivity Then
                Return False
            End If
            If Not Me.IsEditable Then
                Return False
            End If
            Dim activity2 As Activity
            For Each activity2 In activitiesToInsert
                If (activity2 Is Nothing) Then
                    Throw New ArgumentException("activitiesToInsert", SR.GetString("Error_CollectionHasNullEntry"))
                End If
                If (TypeOf activity2 Is CompositeActivity AndAlso Helpers.IsAlternateFlowActivity(activity2)) Then
                    Return False
                End If
                Dim designer As ActivityDesigner = Nothing
                If (Not activity2.Site Is Nothing) Then
                    Dim service As IDesignerHost = [TryCast](activity2.Site.GetService(GetType(IDesignerHost)),IDesignerHost)
                    designer = If((Not service Is Nothing), [TryCast](service.GetDesigner(activity2),ActivityDesigner), Nothing)
                ElseIf activity2.UserData.Contains(GetType(ActivityDesigner)) Then
                    designer = [TryCast](activity2.UserData.Item(GetType(ActivityDesigner)),ActivityDesigner)
                Else
                    designer = ActivityDesigner.CreateDesigner(MyBase.Activity.Site, activity2)
                    activity2.UserData.Item(GetType(ActivityDesigner)) = designer
                End If
                If (designer Is Nothing) Then
                    Return False
                End If
                If Not designer.CanBeParentedTo(Me) Then
                    Return False
                End If
            Next
            Return True
        End Function

        Public Overridable Function CanMoveActivities(ByVal moveLocation As HitTestInfo, ByVal activitiesToMove As ReadOnlyCollection([Of] Activity)) As Boolean
            If (moveLocation Is Nothing) Then
                Throw New ArgumentNullException("moveLocation")
            End If
            If (activitiesToMove Is Nothing) Then
                Throw New ArgumentNullException("activitiesToMove")
            End If
            If Not Me.IsEditable Then
                Return False
            End If
            Dim activity As Activity
            For Each activity In activitiesToMove
                Dim designer As ActivityDesigner = ActivityDesigner.GetDesigner(activity)
                If ((designer Is Nothing) OrElse designer.IsLocked) Then
                    Return False
                End If
            Next
            Return True
        End Function

        Public Overridable Function CanRemoveActivities(ByVal activitiesToRemove As ReadOnlyCollection([Of] Activity)) As Boolean
            If (activitiesToRemove Is Nothing) Then
                Throw New ArgumentNullException("activitiesToRemove")
            End If
            If Not Me.IsEditable Then
                Return False
            End If
            Dim activity As Activity
            For Each activity In activitiesToRemove
                Dim designer As ActivityDesigner = ActivityDesigner.GetDesigner(activity)
                If ((designer Is Nothing) OrElse designer.IsLocked) Then
                    Return False
                End If
            Next
            Return True
        End Function

        Public Shared Function DeserializeActivitiesFromDataObject(ByVal serviceProvider As IServiceProvider, ByVal dataObj As IDataObject) As Activity()
            Return CompositeActivityDesigner.DeserializeActivitiesFromDataObject(serviceProvider, dataObj, False)
        End Function

        Friend Shared Function DeserializeActivitiesFromDataObject(ByVal serviceProvider As IServiceProvider, ByVal dataObj As IDataObject, ByVal addAssemblyReference As Boolean) As Activity()
            If (serviceProvider Is Nothing) Then
                Throw New ArgumentNullException("serviceProvider")
            End If
            If (Not dataObj Is Nothing) Then
                Dim host As IDesignerHost = DirectCast(serviceProvider.GetService(GetType(IDesignerHost)), IDesignerHost)
                If (host Is Nothing) Then
                    Throw New InvalidOperationException(SR.GetString("General_MissingService", New Object() { GetType(IDesignerHost).Name }))
                End If
                Dim data As Object = dataObj.GetData("CF_WINOEDESIGNERCOMPONENTS")
                Dim c As ICollection = Nothing
                If TypeOf data Is Stream Then
                    Dim formatter As New BinaryFormatter
                    DirectCast(data, Stream).Seek(0, SeekOrigin.Begin)
                    Dim obj3 As Object = formatter.Deserialize(DirectCast(data, Stream))
                    If TypeOf obj3 Is SerializationStore Then
                        Dim service As ComponentSerializationService = [TryCast](serviceProvider.GetService(GetType(ComponentSerializationService)),ComponentSerializationService)
                        If (service Is Nothing) Then
                            Throw New Exception(SR.GetString("General_MissingService", New Object() { GetType(ComponentSerializationService).Name }))
                        End If
                        c = service.Deserialize(DirectCast(obj3, SerializationStore))
                    End If
                Else
                    Dim service2 As IToolboxService = DirectCast(serviceProvider.GetService(GetType(IToolboxService)), IToolboxService)
                    If ((Not service2 Is Nothing) AndAlso service2.IsSupported(dataObj, host)) Then
                        Dim item As ToolboxItem = service2.DeserializeToolboxItem(dataObj, host)
                        If (Not item Is Nothing) Then
                            If (addAssemblyReference AndAlso (Not item.AssemblyName Is Nothing)) Then
                                Dim service3 As ITypeResolutionService = [TryCast](serviceProvider.GetService(GetType(ITypeResolutionService)),ITypeResolutionService)
                                If (Not service3 Is Nothing) Then
                                    service3.ReferenceAssembly(item.AssemblyName)
                                End If
                            End If
                            Dim item2 As ActivityToolboxItem = [TryCast](item,ActivityToolboxItem)
                            If (addAssemblyReference AndAlso (Not item2 Is Nothing)) Then
                                c = item2.CreateComponentsWithUI(host)
                            Else
                                c = item.CreateComponents(host)
                            End If
                        End If
                    End If
                End If
                If ((Not c Is Nothing) AndAlso Helpers.AreAllActivities(c)) Then
                    Return DirectCast(New ArrayList(c).ToArray(GetType(Activity)), Activity())
                End If
            End If
            Return New Activity(0  - 1) {}
        End Function

        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                Dim activity As CompositeActivity = [TryCast](MyBase.Activity,CompositeActivity)
                If (Not activity Is Nothing) Then
                    RemoveHandler activity.Activities.ListChanging, New EventHandler([Of] ActivityCollectionChangeEventArgs)(AddressOf Me.OnActivityListChanging)
                    RemoveHandler activity.Activities.ListChanged, New EventHandler([Of] ActivityCollectionChangeEventArgs)(AddressOf Me.OnActivityListChanged)
                End If
                If MyBase.IsRootDesigner Then
                    Dim service As IComponentChangeService = [TryCast](MyBase.GetService(GetType(IComponentChangeService)),IComponentChangeService)
                    If (Not service Is Nothing) Then
                        RemoveHandler service.ComponentAdded, New ComponentEventHandler(AddressOf Me.OnComponentAdded)
                        RemoveHandler service.ComponentChanged, New ComponentChangedEventHandler(AddressOf Me.OnComponentChanged)
                    End If
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        Public Overridable Sub EnsureVisibleContainedDesigner(ByVal containedDesigner As ActivityDesigner)
            If (containedDesigner Is Nothing) Then
                Throw New ArgumentNullException("containedDesigner")
            End If
            Me.Expanded = True
        End Sub

        Public Shared Function GetIntersectingDesigners(ByVal topLevelDesigner As ActivityDesigner, ByVal rectangle As Rectangle) As ActivityDesigner()
            If (topLevelDesigner Is Nothing) Then
                Throw New ArgumentNullException("topLevelDesigner")
            End If
            Dim list As New List([Of] ActivityDesigner)
            If Not rectangle.IntersectsWith(topLevelDesigner.Bounds) Then
                Return list.ToArray
            End If
            If Not topLevelDesigner.Bounds.Contains(rectangle) Then
                list.Add(topLevelDesigner)
            End If
            If Not TypeOf topLevelDesigner Is CompositeActivityDesigner Then
                goto Label_0103
            End If
            Dim queue As New Queue
            queue.Enqueue(topLevelDesigner)
        Label_00F7:
            Do While (queue.Count > 0)
                Dim designer As CompositeActivityDesigner = [TryCast](queue.Dequeue,CompositeActivityDesigner)
                If (Not designer Is Nothing) Then
                    Dim flag As Boolean = False
                    Dim designer2 As ActivityDesigner
                    For Each designer2 In designer.ContainedDesigners
                        If (designer2.IsVisible AndAlso rectangle.IntersectsWith(designer2.Bounds)) Then
                            flag = True
                            If Not designer2.Bounds.Contains(rectangle) Then
                                list.Add(designer2)
                            End If
                            If TypeOf designer2 Is CompositeActivityDesigner Then
                                queue.Enqueue(designer2)
                            End If
                            [Continue] For
                        End If
                        If (Not TypeOf designer Is FreeformActivityDesigner AndAlso flag) Then
                            goto Label_00F7
                        End If
                    Next
                End If
            Loop
        Label_0103:
            Return list.ToArray
        End Function

        Public Overridable Function GetNextSelectableObject(ByVal current As Object, ByVal direction As DesignerNavigationDirection) As Object
            Return Nothing
        End Function

        Public Overrides Function HitTest(ByVal point As Point) As HitTestInfo
            Dim nowhere As HitTestInfo = HitTestInfo.Nowhere
            If Me.ExpandButtonRectangle.Contains(point) Then
                nowhere = New HitTestInfo(Me, (HitTestLocations.ActionArea Or HitTestLocations.Designer))
            ElseIf (Me.Expanded AndAlso MyBase.Bounds.Contains(point)) Then
                Dim containedDesigners As ReadOnlyCollection([Of] ActivityDesigner) = Me.ContainedDesigners
                Dim i As Integer = (containedDesigners.Count - 1)
                Do While (i >= 0)
                    Dim designer As ActivityDesigner = containedDesigners.Item(i)
                    If ((Not designer Is Nothing) AndAlso designer.IsVisible) Then
                        nowhere = designer.HitTest(point)
                        If (nowhere.HitLocation <> HitTestLocations.None) Then
                            Exit Do
                        End If
                    End If
                    i -= 1
                Loop
            End If
            If (nowhere Is HitTestInfo.Nowhere) Then
                nowhere = MyBase.HitTest(point)
            End If
            If ((Not nowhere.AssociatedDesigner Is Nothing) AndAlso (nowhere.AssociatedDesigner.DrawingState <> DrawingStates.Valid)) Then
                nowhere = New HitTestInfo(nowhere.AssociatedDesigner, (HitTestLocations.ActionArea Or HitTestLocations.Designer))
            End If
            Return nowhere
        End Function

        Protected Overrides Sub Initialize(ByVal activity As Activity)
            MyBase.Initialize(activity)
            Dim activity2 As CompositeActivity = [TryCast](activity,CompositeActivity)
            If (Not activity2 Is Nothing) Then
                AddHandler activity2.Activities.ListChanging, New EventHandler([Of] ActivityCollectionChangeEventArgs)(AddressOf Me.OnActivityListChanging)
                AddHandler activity2.Activities.ListChanged, New EventHandler([Of] ActivityCollectionChangeEventArgs)(AddressOf Me.OnActivityListChanged)
            End If
            If MyBase.IsRootDesigner Then
                Dim service As IComponentChangeService = [TryCast](MyBase.GetService(GetType(IComponentChangeService)),IComponentChangeService)
                If (Not service Is Nothing) Then
                    AddHandler service.ComponentAdded, New ComponentEventHandler(AddressOf Me.OnComponentAdded)
                    AddHandler service.ComponentChanged, New ComponentChangedEventHandler(AddressOf Me.OnComponentChanged)
                End If
            End If
        End Sub

        Public Overridable Sub InsertActivities(ByVal insertLocation As HitTestInfo, ByVal activitiesToInsert As ReadOnlyCollection([Of] Activity))
            Dim handler As WalkerEventHandler = Nothing
            If (insertLocation Is Nothing) Then
                Throw New ArgumentNullException("insertLocation")
            End If
            If (activitiesToInsert Is Nothing) Then
                Throw New ArgumentNullException("activitiesToInsert")
            End If
            Dim parentActivity As CompositeActivity = [TryCast](MyBase.Activity,CompositeActivity)
            If (parentActivity Is Nothing) Then
                Throw New Exception(SR.GetString("Error_DragDropInvalid"))
            End If
            Dim num As Integer = insertLocation.MapToIndex
            Dim service As IIdentifierCreationService = [TryCast](MyBase.GetService(GetType(IIdentifierCreationService)),IIdentifierCreationService)
            If (service Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString("General_MissingService", New Object() { GetType(IIdentifierCreationService).FullName }))
            End If
            service.EnsureUniqueIdentifiers(parentActivity, activitiesToInsert)
            Dim activity2 As Activity
            For Each activity2 In activitiesToInsert
                If (activity2 Is Nothing) Then
                    Throw New ArgumentException("activitiesToInsert", SR.GetString("Error_CollectionHasNullEntry"))
                End If
                If (activity2.Parent Is Nothing) Then
                    parentActivity.Activities.Insert(num++, activity2)
                    WorkflowDesignerLoader.AddActivityToDesigner(MyBase.Activity.Site, activity2)
                End If
            Next
            Dim activity3 As Activity
            For Each activity3 In activitiesToInsert
                Dim walker As New Walker
                If (handler Is Nothing) Then
                    handler = Function (ByVal w As Walker, ByVal walkerEventArgs As WalkerEventArgs) 
                        ExtenderHelpers.FilterDependencyProperties(MyBase.Activity.Site, walkerEventArgs.CurrentActivity)
                    End Function
                End If
                AddHandler walker.FoundActivity, handler
                walker.Walk(activity3)
            Next
        End Sub

        Public Shared Sub InsertActivities(ByVal compositeActivityDesigner As CompositeActivityDesigner, ByVal insertLocation As HitTestInfo, ByVal activitiesToInsert As ReadOnlyCollection([Of] Activity), ByVal undoTransactionDescription As String)
            If (compositeActivityDesigner Is Nothing) Then
                Throw New ArgumentNullException("compositeActivityDesigner")
            End If
            If (((compositeActivityDesigner.Activity Is Nothing) OrElse (compositeActivityDesigner.Activity.Site Is Nothing)) OrElse Not TypeOf compositeActivityDesigner.Activity Is CompositeActivity) Then
                Throw New ArgumentException("compositeActivityDesigner")
            End If
            If (insertLocation Is Nothing) Then
                Throw New ArgumentNullException("insertLocation")
            End If
            If (activitiesToInsert Is Nothing) Then
                Throw New ArgumentNullException("activitiesToInsert")
            End If
            Dim service As IDesignerHost = [TryCast](compositeActivityDesigner.Activity.Site.GetService(GetType(IDesignerHost)),IDesignerHost)
            Dim transaction As DesignerTransaction = Nothing
            If ((Not service Is Nothing) AndAlso Not String.IsNullOrEmpty(undoTransactionDescription)) Then
                transaction = service.CreateTransaction(undoTransactionDescription)
            End If
            Dim flag As Boolean = False
            Try 
                Dim activity As Activity
                For Each activity In activitiesToInsert
                    If (activity Is Nothing) Then
                        Throw New ArgumentException("activitiesToInsert", SR.GetString("Error_CollectionHasNullEntry"))
                    End If
                    flag = (Not activity.Site Is Nothing)
                    Exit For
                Next
                If flag Then
                    compositeActivityDesigner.MoveActivities(insertLocation, activitiesToInsert)
                Else
                    compositeActivityDesigner.InsertActivities(insertLocation, activitiesToInsert)
                End If
                If (Not transaction Is Nothing) Then
                    transaction.Commit
                End If
            Catch exception As Exception
                If (Not transaction Is Nothing) Then
                    transaction.Cancel
                End If
                Throw exception
            End Try
            If Not flag Then
                Dim list As New ArrayList
                Dim activity2 As Activity
                For Each activity2 In activitiesToInsert
                    list.Add(activity2)
                    If TypeOf activity2 Is CompositeActivity Then
                        list.AddRange(Helpers.GetNestedActivities(DirectCast(activity2, CompositeActivity)))
                    End If
                Next
            End If
        End Sub

        Public Overridable Function IsContainedDesignerVisible(ByVal containedDesigner As ActivityDesigner) As Boolean
            If (containedDesigner Is Nothing) Then
                Throw New ArgumentNullException("containedDesigner")
            End If
            Return True
        End Function

        Protected Overrides Sub LoadViewState(ByVal reader As BinaryReader)
            If (reader Is Nothing) Then
                Throw New ArgumentNullException("reader")
            End If
            Me.Expanded = reader.ReadBoolean
            MyBase.LoadViewState(reader)
        End Sub

        Public Overridable Sub MoveActivities(ByVal moveLocation As HitTestInfo, ByVal activitiesToMove As ReadOnlyCollection([Of] Activity))
            Dim handler As WalkerEventHandler = Nothing
            If (moveLocation Is Nothing) Then
                Throw New ArgumentNullException("moveLocation")
            End If
            If (activitiesToMove Is Nothing) Then
                Throw New ArgumentNullException("activitiesToMove")
            End If
            Dim parentActivity As CompositeActivity = [TryCast](MyBase.Activity,CompositeActivity)
            If (parentActivity Is Nothing) Then
                Throw New Exception(SR.GetString("Error_DragDropInvalid"))
            End If
            Dim service As IIdentifierCreationService = [TryCast](MyBase.GetService(GetType(IIdentifierCreationService)),IIdentifierCreationService)
            If (service Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString("General_MissingService", New Object() { GetType(IIdentifierCreationService).FullName }))
            End If
            If Not TypeOf MyBase.GetService(GetType(IDesignerHost)) Is IDesignerHost Then
                Throw New InvalidOperationException(SR.GetString("General_MissingService", New Object() { GetType(IDesignerHost).FullName }))
            End If
            Dim num As Integer = moveLocation.MapToIndex
            Dim activity2 As Activity
            For Each activity2 In activitiesToMove
                Dim designer As ActivityDesigner = ActivityDesigner.GetDesigner(activity2)
                If ((Not designer Is Nothing) AndAlso (designer.ParentDesigner Is Me)) Then
                    Dim num2 As Integer = parentActivity.Activities.IndexOf(activity2)
                    If (num > num2) Then
                        num -= 1
                    End If
                End If
                Dim parent As CompositeActivity = activity2.Parent
                Dim index As Integer = parent.Activities.IndexOf(activity2)
                activity2.Parent.Activities.Remove(activity2)
                service.EnsureUniqueIdentifiers(parentActivity, New Activity() { activity2 })
                DesignerHelpers.UpdateSiteName(activity2, "_activityonthemove_")
                Dim compositeActivity As CompositeActivity = [TryCast](activity2,CompositeActivity)
                If (Not compositeActivity Is Nothing) Then
                    Dim num4 As Integer = 1
                    Dim activity5 As Activity
                    For Each activity5 In Helpers.GetNestedActivities(compositeActivity)
                        DesignerHelpers.UpdateSiteName(activity5, ("_activityonthemove_" & num4.ToString(CultureInfo.InvariantCulture)))
                        num4 += 1
                    Next
                End If
                Try 
                    parentActivity.Activities.Insert(num++, activity2)
                Catch exception As Exception
                    parent.Activities.Insert(index, activity2)
                    Throw exception
                End Try
                DesignerHelpers.UpdateSiteName(activity2, activity2.Name)
                If (Not compositeActivity Is Nothing) Then
                    Dim activity6 As Activity
                    For Each activity6 In Helpers.GetNestedActivities(compositeActivity)
                        DesignerHelpers.UpdateSiteName(activity6, activity6.Name)
                    Next
                End If
            Next
            Dim activity7 As Activity
            For Each activity7 In activitiesToMove
                Dim walker As New Walker
                If (handler Is Nothing) Then
                    handler = Function (ByVal w As Walker, ByVal walkerEventArgs As WalkerEventArgs) 
                        ExtenderHelpers.FilterDependencyProperties(MyBase.Activity.Site, walkerEventArgs.CurrentActivity)
                        TypeDescriptor.Refresh(walkerEventArgs.CurrentActivity)
                    End Function
                End If
                AddHandler walker.FoundActivity, handler
                walker.Walk(activity7)
            Next
        End Sub

        Public Shared Sub MoveDesigners(ByVal activityDesigner As ActivityDesigner, ByVal moveBack As Boolean)
            If (activityDesigner Is Nothing) Then
                Throw New ArgumentNullException("activityDesigner")
            End If
            Dim item As Activity = activityDesigner.Activity
            If ((Not item Is Nothing) AndAlso (Not item.Parent Is Nothing)) Then
                Dim parent As CompositeActivity = item.Parent
                If ((Not parent Is Nothing) AndAlso parent.Activities.Contains(item)) Then
                    Dim index As Integer = (parent.Activities.IndexOf(item) + If(moveBack, -1, 1))
                    If ((index >= 0) AndAlso (index < parent.Activities.Count)) Then
                        Dim host As IDesignerHost = [TryCast](parent.Site.GetService(GetType(IDesignerHost)),IDesignerHost)
                        If (Not host Is Nothing) Then
                            Dim transaction As DesignerTransaction = host.CreateTransaction(SR.GetString("MovingActivities"))
                            Try 
                                parent.Activities.Remove(item)
                                parent.Activities.Insert(index, item)
                                Dim service As ISelectionService = [TryCast](parent.Site.GetService(GetType(ISelectionService)),ISelectionService)
                                If (Not service Is Nothing) Then
                                    service.SetSelectedComponents(New Object() { item })
                                End If
                                If (Not transaction Is Nothing) Then
                                    transaction.Commit
                                End If
                            Catch obj1 As Object
                                If (Not transaction Is Nothing) Then
                                    transaction.Cancel
                                End If
                                Throw
                            End Try
                            Dim designer As CompositeActivityDesigner = [TryCast](ActivityDesigner.GetDesigner(parent),CompositeActivityDesigner)
                            If (Not designer Is Nothing) Then
                                designer.PerformLayout
                            End If
                        End If
                    End If
                End If
            End If
        End Sub

        Private Sub OnActivityListChanged(ByVal sender As Object, ByVal e As ActivityCollectionChangeEventArgs)
            Me.OnContainedActivitiesChanged(e)
        End Sub

        Private Sub OnActivityListChanging(ByVal sender As Object, ByVal e As ActivityCollectionChangeEventArgs)
            Me.OnContainedActivitiesChanging(e)
        End Sub

        Private Sub OnComponentAdded(ByVal sender As Object, ByVal e As ComponentEventArgs)
            Dim designer As ActivityDesigner = ActivityDesigner.GetDesigner([TryCast](e.Component,Activity))
            If (((Not MyBase.Activity Is e.Component) AndAlso (Not designer Is Nothing)) AndAlso designer.IsLocked) Then
                DesignerHelpers.MakePropertiesReadOnly(e.Component.Site, designer.Activity)
            End If
        End Sub

        Private Sub OnComponentChanged(ByVal sender As Object, ByVal e As ComponentChangedEventArgs)
            Dim service As IReferenceService = [TryCast](MyBase.GetService(GetType(IReferenceService)),IReferenceService)
            Dim activity As Activity = If((Not service Is Nothing), [TryCast](service.GetComponent(e.Component),Activity), [TryCast](e.Component,Activity))
            If (Not activity Is Nothing) Then
                Dim designer As ActivityDesigner = ActivityDesigner.GetDesigner(activity)
                If (Not designer Is Nothing) Then
                    Dim parentDesigner As CompositeActivityDesigner = designer.ParentDesigner
                    If (Not parentDesigner Is Nothing) Then
                        parentDesigner.OnContainedActivityChanged(New ActivityChangedEventArgs(activity, e.Member, e.OldValue, e.NewValue))
                    End If
                End If
            End If
        End Sub

        Protected Overridable Sub OnContainedActivitiesChanged(ByVal listChangeArgs As ActivityCollectionChangeEventArgs)
            If (listChangeArgs Is Nothing) Then
                Throw New ArgumentNullException("listChangeArgs")
            End If
            Dim designer As ActivityDesigner
            For Each designer In Me.ContainedDesigners
                Dim verb As DesignerVerb
                For Each verb In DirectCast(designer, IDesigner).Verbs
                    Dim oleStatus As Integer = verb.OleStatus
                Next
            Next
            MyBase.RefreshDesignerVerbs
            Me.containedActivityDesigners = Nothing
            MyBase.PerformLayout
        End Sub

        Protected Overridable Sub OnContainedActivitiesChanging(ByVal listChangeArgs As ActivityCollectionChangeEventArgs)
            If (listChangeArgs Is Nothing) Then
                Throw New ArgumentNullException("listChangeArgs")
            End If
        End Sub

        Protected Overridable Sub OnContainedActivityChanged(ByVal e As ActivityChangedEventArgs)
            If (e Is Nothing) Then
                Throw New ArgumentNullException("e")
            End If
        End Sub

        Protected Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
            If (e Is Nothing) Then
                Throw New ArgumentNullException("e")
            End If
            Dim service As ISelectionService = [TryCast](MyBase.GetService(GetType(ISelectionService)),ISelectionService)
            Dim activity As Object = If((Not service Is Nothing), service.PrimarySelection, Nothing)
            If (activity Is Nothing) Then
                Return
            End If
            Dim selectableObject As Object = Nothing
            If ((e.KeyCode = Keys.Down) OrElse ((e.KeyCode = Keys.Tab) AndAlso Not e.Shift)) Then
                Dim designer As CompositeActivityDesigner = [TryCast](ActivityDesigner.GetDesigner([TryCast](activity,Activity)),CompositeActivityDesigner)
                If (Not designer Is Nothing) Then
                    selectableObject = designer.FirstSelectableObject
                End If
                If (Not selectableObject Is Nothing) Then
                    goto Label_0188
                End If
                Do While True
                    Dim parentDesigner As CompositeActivityDesigner = ActivityDesigner.GetParentDesigner(activity)
                    If (parentDesigner Is Nothing) Then
                        selectableObject = activity
                        goto Label_0188
                    End If
                    selectableObject = parentDesigner.GetNextSelectableObject(activity, DesignerNavigationDirection.Down)
                    If (Not selectableObject Is Nothing) Then
                        goto Label_0188
                    End If
                    activity = parentDesigner.Activity
                Loop
            End If
            If ((e.KeyCode = Keys.Up) OrElse ((e.KeyCode = Keys.Tab) AndAlso e.Shift)) Then
                Dim designer3 As CompositeActivityDesigner = ActivityDesigner.GetParentDesigner(activity)
                If (designer3 Is Nothing) Then
                    Dim designer4 As CompositeActivityDesigner = [TryCast](ActivityDesigner.GetDesigner([TryCast](activity,Activity)),CompositeActivityDesigner)
                    If (Not designer4 Is Nothing) Then
                        selectableObject = designer4.LastSelectableObject
                    End If
                Else
                    selectableObject = designer3.GetNextSelectableObject(activity, DesignerNavigationDirection.Up)
                    If (Not selectableObject Is Nothing) Then
                        Dim designer5 As CompositeActivityDesigner = [TryCast](ActivityDesigner.GetDesigner([TryCast](selectableObject,Activity)),CompositeActivityDesigner)
                        If (Not designer5 Is Nothing) Then
                            Dim lastSelectableObject As Object = designer5.LastSelectableObject
                            If (Not lastSelectableObject Is Nothing) Then
                                selectableObject = lastSelectableObject
                            End If
                        End If
                    Else
                        selectableObject = designer3.Activity
                    End If
                End If
            Else
                If (e.KeyCode = Keys.Left) Then
                    Do While True
                        Dim designer6 As CompositeActivityDesigner = ActivityDesigner.GetParentDesigner(activity)
                        If (designer6 Is Nothing) Then
                            goto Label_0188
                        End If
                        selectableObject = designer6.GetNextSelectableObject(activity, DesignerNavigationDirection.Left)
                        If (Not selectableObject Is Nothing) Then
                            goto Label_0188
                        End If
                        activity = designer6.Activity
                    Loop
                End If
                If (e.KeyCode = Keys.Right) Then
                    Do While True
                        Dim designer7 As CompositeActivityDesigner = ActivityDesigner.GetParentDesigner(activity)
                        If (designer7 Is Nothing) Then
                            Exit Do
                        End If
                        selectableObject = designer7.GetNextSelectableObject(activity, DesignerNavigationDirection.Right)
                        If (Not selectableObject Is Nothing) Then
                            Exit Do
                        End If
                        activity = designer7.Activity
                    Loop
                End If
            End If
        Label_0188:
            If (Not selectableObject Is Nothing) Then
                service.SetSelectedComponents(New Object() { selectableObject }, SelectionTypes.Replace)
                MyBase.ParentView.EnsureVisible(selectableObject)
            End If
        End Sub

        Protected Overrides Sub OnLayoutPosition(ByVal e As ActivityDesignerLayoutEventArgs)
            If (e Is Nothing) Then
                Throw New ArgumentNullException("e")
            End If
            MyBase.OnLayoutPosition(e)
            Dim designer As ActivityDesigner
            For Each designer In Me.ContainedDesigners
                Try 
                    DirectCast(designer, IWorkflowDesignerMessageSink).OnLayoutPosition(e.Graphics)
                    designer.DrawingState = (designer.DrawingState And Not DrawingStates.InvalidPosition)
                    [Continue] For
                Catch obj1 As Object
                    designer.DrawingState = (designer.DrawingState Or DrawingStates.InvalidPosition)
                    [Continue] For
                End Try
            Next
        End Sub

        Protected Overrides Function OnLayoutSize(ByVal e As ActivityDesignerLayoutEventArgs) As Size
            Dim size As Size = MyBase.OnLayoutSize(e)
            Dim designer As ActivityDesigner
            For Each designer In Me.ContainedDesigners
                Try 
                    DirectCast(designer, IWorkflowDesignerMessageSink).OnLayoutSize(e.Graphics)
                    designer.DrawingState = (designer.DrawingState And Not DrawingStates.InvalidSize)
                    [Continue] For
                Catch obj1 As Object
                    designer.Size = designer.DesignerTheme.Size
                    designer.DrawingState = (designer.DrawingState Or DrawingStates.InvalidSize)
                    [Continue] For
                End Try
            Next
            If Not String.IsNullOrEmpty(Me.Text) Then
                Me.actualTextSize = ActivityDesignerPaint.MeasureString(e.Graphics, e.DesignerTheme.BoldFont, Me.Text, StringAlignment.Center, Size.Empty)
            Else
                Me.actualTextSize = Size.Empty
            End If
            If Me.Expanded Then
                size.Height = Me.TitleHeight
                Return size
            End If
            size.Height = (Me.TitleHeight + WorkflowTheme.CurrentTheme.AmbientTheme.Margin.Height)
            Return size
        End Function

        Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
            MyBase.OnMouseDown(e)
            If Me.ExpandButtonRectangle.Contains(New Point(e.X, e.Y)) Then
                Dim service As IMenuCommandService = [TryCast](MyBase.GetService(GetType(IMenuCommandService)),IMenuCommandService)
                If (Not service Is Nothing) Then
                    service.GlobalInvoke(If(Me.Expanded, WorkflowMenuCommands.Collapse, WorkflowMenuCommands.Expand))
                Else
                    Me.Expanded = Not Me.Expanded
                End If
            End If
        End Sub

        Protected Overrides Sub OnPaint(ByVal e As ActivityDesignerPaintEventArgs)
            MyBase.OnPaint(e)
            Dim designerTheme As CompositeDesignerTheme = [TryCast](e.DesignerTheme,CompositeDesignerTheme)
            If (Not designerTheme Is Nothing) Then
                If Me.CanExpandCollapse Then
                    Dim expandButtonRectangle As Rectangle = Me.ExpandButtonRectangle
                    If Not expandButtonRectangle.Size.IsEmpty Then
                        ActivityDesignerPaint.DrawExpandButton(e.Graphics, expandButtonRectangle, Not Me.Expanded, designerTheme)
                    End If
                End If
                If Me.Expanded Then
                    Me.PaintContainedDesigners(e)
                End If
            End If
        End Sub

        Friend Overridable Sub OnPaintContainedDesigners(ByVal e As ActivityDesignerPaintEventArgs)
            Dim designer As ActivityDesigner
            For Each designer In Me.ContainedDesigners
                DirectCast(designer, IWorkflowDesignerMessageSink).OnPaint(New PaintEventArgs(e.Graphics, e.ViewPort), e.ViewPort)
            Next
        End Sub

        Protected Overrides Sub OnThemeChange(ByVal designerTheme As ActivityDesignerTheme)
            MyBase.OnThemeChange(designerTheme)
            Dim activity As CompositeActivity = [TryCast](MyBase.Activity,CompositeActivity)
            If (Not activity Is Nothing) Then
                Dim activity2 As Activity
                For Each activity2 In activity.Activities
                    Dim designer As IWorkflowDesignerMessageSink = ActivityDesigner.GetDesigner(activity2)
                    If (Not designer Is Nothing) Then
                        designer.OnThemeChange
                    End If
                Next
            End If
        End Sub

        Protected Sub PaintContainedDesigners(ByVal e As ActivityDesignerPaintEventArgs)
            Me.OnPaintContainedDesigners(e)
        End Sub

        Public Overridable Sub RemoveActivities(ByVal activitiesToRemove As ReadOnlyCollection([Of] Activity))
            If (activitiesToRemove Is Nothing) Then
                Throw New ArgumentNullException("activitiesToRemove")
            End If
            Dim activity As CompositeActivity = [TryCast](MyBase.Activity,CompositeActivity)
            If (activity Is Nothing) Then
                Throw New Exception(SR.GetString("Error_DragDropInvalid"))
            End If
            Dim activity2 As Activity
            For Each activity2 In activitiesToRemove
                activity.Activities.Remove(activity2)
                activity2.SetParent(Nothing)
                If TypeOf activity2 Is CompositeActivity Then
                    Dim activity3 As Activity
                    For Each activity3 In Helpers.GetNestedActivities([TryCast](activity2,CompositeActivity))
                        activity3.SetParent(Nothing)
                    Next
                End If
                WorkflowDesignerLoader.RemoveActivityFromDesigner(MyBase.Activity.Site, activity2)
            Next
        End Sub

        Public Shared Sub RemoveActivities(ByVal serviceProvider As IServiceProvider, ByVal activitiesToRemove As ReadOnlyCollection([Of] Activity), ByVal transactionDescription As String)
            If (serviceProvider Is Nothing) Then
                Throw New ArgumentNullException
            End If
            If (activitiesToRemove Is Nothing) Then
                Throw New ArgumentNullException("activitiesToRemove")
            End If
            Dim nextSelectableActivity As Activity = Nothing
            Dim host As IDesignerHost = [TryCast](serviceProvider.GetService(GetType(IDesignerHost)),IDesignerHost)
            Dim transaction As DesignerTransaction = Nothing
            If ((Not host Is Nothing) AndAlso Not String.IsNullOrEmpty(transactionDescription)) Then
                transaction = host.CreateTransaction(transactionDescription)
            End If
            Try 
                Dim activity2 As Activity
                For Each activity2 In activitiesToRemove
                    Dim designer As ActivityDesigner = ActivityDesigner.GetDesigner(activity2)
                    If (Not designer Is Nothing) Then
                        Dim parentDesigner As CompositeActivityDesigner = designer.ParentDesigner
                        If (Not parentDesigner Is Nothing) Then
                            nextSelectableActivity = DesignerHelpers.GetNextSelectableActivity(activity2)
                            parentDesigner.RemoveActivities(New List([Of] Activity)(New Activity() { activity2 }).AsReadOnly)
                        End If
                    End If
                Next
                If (Not transaction Is Nothing) Then
                    transaction.Commit
                End If
            Catch obj1 As Object
                If (Not transaction Is Nothing) Then
                    transaction.Cancel
                End If
                Throw
            End Try
            If ((Not nextSelectableActivity Is Nothing) AndAlso (Not nextSelectableActivity.Site Is Nothing)) Then
                Dim service As ISelectionService = [TryCast](nextSelectableActivity.Site.GetService(GetType(ISelectionService)),ISelectionService)
                If (Not service Is Nothing) Then
                    service.SetSelectedComponents(New Activity() { nextSelectableActivity }, SelectionTypes.Replace)
                End If
            End If
        End Sub

        Protected Overrides Sub SaveViewState(ByVal writer As BinaryWriter)
            If (writer Is Nothing) Then
                Throw New ArgumentNullException("writer")
            End If
            writer.Write(Me.Expanded)
            MyBase.SaveViewState(writer)
        End Sub

        Public Shared Function SerializeActivitiesToDataObject(ByVal serviceProvider As IServiceProvider, ByVal activities As Activity()) As IDataObject
            If (serviceProvider Is Nothing) Then
                Throw New ArgumentNullException("serviceProvider")
            End If
            If (activities Is Nothing) Then
                Throw New ArgumentNullException("activities")
            End If
            Dim service As ComponentSerializationService = DirectCast(serviceProvider.GetService(GetType(ComponentSerializationService)), ComponentSerializationService)
            If (service Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString("General_MissingService", New Object() { GetType(ComponentSerializationService).Name }))
            End If
            Dim store As SerializationStore = service.CreateStore
            [Using] store
                Dim activity As Activity
                For Each activity In activities
                    service.Serialize(store, activity)
                Next
            End [Using]
            Dim serializationStream As Stream = New MemoryStream
            New BinaryFormatter().Serialize(serializationStream, store)
            serializationStream.Seek(0, SeekOrigin.Begin)
            Dim obj2 As New DataObject("CF_WINOEDESIGNERCOMPONENTS", serializationStream)
            obj2.SetData("CF_WINOEDESIGNERCOMPONENTSSTATE", Helpers.SerializeDesignersToStream(activities))
            Return obj2
        End Function


        ' Properties
        Public Overrides ReadOnly Property AccessibilityObject As AccessibleObject
            Get
                If (Me.accessibilityObject Is Nothing) Then
                    Me.accessibilityObject = New CompositeDesignerAccessibleObject(Me)
                End If
                Return Me.accessibilityObject
            End Get
        End Property

        Public Overridable ReadOnly Property CanExpandCollapse As Boolean
            Get
                Return Not MyBase.IsRootDesigner
            End Get
        End Property

        Public Overridable ReadOnly Property ContainedDesigners As ReadOnlyCollection([Of] ActivityDesigner)
            Get
                Dim containedActivityDesigners As New List([Of] ActivityDesigner)
                Dim activity As CompositeActivity = [TryCast](MyBase.Activity,CompositeActivity)
                If (Not activity Is Nothing) Then
                    If (Me.containedActivityDesigners Is Nothing) Then
                        Dim flag As Boolean = True
                        Dim activity2 As Activity
                        For Each activity2 In activity.Activities
                            Dim item As ActivityDesigner = ActivityDesigner.GetDesigner(activity2)
                            If (Not item Is Nothing) Then
                                containedActivityDesigners.Add(item)
                            Else
                                flag = False
                            End If
                        Next
                        If flag Then
                            Me.containedActivityDesigners = containedActivityDesigners
                        End If
                    Else
                        containedActivityDesigners = Me.containedActivityDesigners
                    End If
                End If
                Return containedActivityDesigners.AsReadOnly
            End Get
        End Property

        <EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
        Friend ReadOnly Property Designers As List([Of] ActivityDesigner)
            Get
                Dim list As New List([Of] ActivityDesigner)
                Dim activity As CompositeActivity = [TryCast](MyBase.Activity,CompositeActivity)
                Dim service As IDesignerHost = [TryCast](MyBase.GetService(GetType(IDesignerHost)),IDesignerHost)
                If ((Not service Is Nothing) AndAlso (Not activity Is Nothing)) Then
                    Dim activity2 As Activity
                    For Each activity2 In activity.Activities
                        Dim item As ActivityDesigner = [TryCast](service.GetDesigner(activity2),ActivityDesigner)
                        If (Not item Is Nothing) Then
                            list.Add(item)
                        End If
                    Next
                End If
                Return list
            End Get
        End Property

        Protected Overridable ReadOnly Property ExpandButtonRectangle As Rectangle
            Get
                Dim rectangle2 As Rectangle
                If Not Me.CanExpandCollapse Then
                    Return Rectangle.Empty
                End If
                Dim designerTheme As CompositeDesignerTheme = [TryCast](MyBase.DesignerTheme,CompositeDesignerTheme)
                If (designerTheme Is Nothing) Then
                    Return Rectangle.Empty
                End If
                Dim size As Size = Me.TextRectangle.Size
                Dim size2 As Size = If((Not Me.Image Is Nothing), designerTheme.ImageSize, Size.Empty)
                Dim bounds As Rectangle = MyBase.Bounds
                Dim size3 As Size = If(Not size.IsEmpty, size, size2)
                rectangle2 = New Rectangle(bounds.Location, designerTheme.ExpandButtonSize) { _
                    .X = (rectangle2.X + ((bounds.Width - (((3 * designerTheme.ExpandButtonSize.Width) / 2) + size3.Width)) / 2)), _
                    .Y = (rectangle2.Y + (2 * WorkflowTheme.CurrentTheme.AmbientTheme.Margin.Height)) _
                }
                If (size3.Height > rectangle2.Height) Then
                    rectangle2.Y = (rectangle2.Y + ((size3.Height - rectangle2.Height) / 2))
                End If
                Return rectangle2
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Overridable Property Expanded As Boolean
            Get
                If (Not Me.CanExpandCollapse AndAlso Not Me.expanded) Then
                    Me.Expanded = True
                End If
                Return Me.expanded
            End Get
            Set(ByVal value As Boolean)
                If ((Me.expanded <> value) AndAlso (Me.CanExpandCollapse OrElse value)) Then
                    Me.expanded = value
                    MyBase.PerformLayout
                End If
            End Set
        End Property

        Public Overridable ReadOnly Property FirstSelectableObject As Object
            Get
                Return Nothing
            End Get
        End Property

        Protected Friend Overrides ReadOnly Property Glyphs As ActivityDesignerGlyphCollection
            Get
                Dim glyphs As New ActivityDesignerGlyphCollection
                glyphs.AddRange(MyBase.Glyphs)
                Dim designerTheme As CompositeDesignerTheme = [TryCast](MyBase.DesignerTheme,CompositeDesignerTheme)
                If ((Not designerTheme Is Nothing) AndAlso designerTheme.ShowDropShadow) Then
                    glyphs.Add(ShadowGlyph.Default)
                End If
                Return glyphs
            End Get
        End Property

        Protected Overrides ReadOnly Property ImageRectangle As Rectangle
            Get
                If (Me.Image Is Nothing) Then
                    Return Rectangle.Empty
                End If
                Dim designerTheme As CompositeDesignerTheme = [TryCast](MyBase.DesignerTheme,CompositeDesignerTheme)
                If (designerTheme Is Nothing) Then
                    Return Rectangle.Empty
                End If
                Dim bounds As Rectangle = MyBase.Bounds
                Dim size As Size = Me.ExpandButtonRectangle.Size
                Dim imageSize As Size = designerTheme.ImageSize
                Dim size3 As Size = Me.TextRectangle.Size
                Dim margin As Size = WorkflowTheme.CurrentTheme.AmbientTheme.Margin
                Dim rectangle2 As New Rectangle(bounds.Location, imageSize)
                If (size3.Width > 0) Then
                    rectangle2.X = (rectangle2.X + ((bounds.Width - imageSize.Width) / 2))
                Else
                    rectangle2.X = (rectangle2.X + ((bounds.Width - (imageSize.Width + ((3 * size.Width) / 2))) / 2))
                    rectangle2.X = (rectangle2.X + ((3 * size.Width) / 2))
                End If
                rectangle2.Y = (rectangle2.Y + (2 * margin.Height))
                If (size3.Height > 0) Then
                    rectangle2.Y = (rectangle2.Y + (size3.Height + margin.Height))
                End If
                Return rectangle2
            End Get
        End Property

        Public ReadOnly Property IsEditable As Boolean
            Get
                If Not TypeOf MyBase.Activity Is CompositeActivity Then
                    Return False
                End If
                If MyBase.IsLocked Then
                    Return False
                End If
                If Helpers.IsCustomActivity([TryCast](MyBase.Activity,CompositeActivity)) Then
                    Return False
                End If
                Return True
            End Get
        End Property

        Public Overridable ReadOnly Property LastSelectableObject As Object
            Get
                Return Nothing
            End Get
        End Property

        Public Overrides Property Location As Point
            Get
                Return MyBase.Location
            End Get
            Set(ByVal value As Point)
                If (MyBase.Location <> value) Then
                    Dim size As New Size((value.X - MyBase.Location.X), (value.Y - MyBase.Location.Y))
                    Dim designer As ActivityDesigner
                    For Each designer In Me.ContainedDesigners
                        designer.Location = New Point((designer.Location.X + size.Width), (designer.Location.Y + size.Height))
                    Next
                    MyBase.Location = value
                End If
            End Set
        End Property

        Protected Overrides ReadOnly Property TextRectangle As Rectangle
            Get
                Dim rectangle2 As Rectangle
                If String.IsNullOrEmpty(Me.Text) Then
                    Return Rectangle.Empty
                End If
                Dim designerTheme As CompositeDesignerTheme = [TryCast](MyBase.DesignerTheme,CompositeDesignerTheme)
                If (designerTheme Is Nothing) Then
                    Return Rectangle.Empty
                End If
                Dim bounds As Rectangle = MyBase.Bounds
                Dim margin As Size = WorkflowTheme.CurrentTheme.AmbientTheme.Margin
                Dim size2 As Size = If(Me.CanExpandCollapse, designerTheme.ExpandButtonSize, Size.Empty)
                Dim num As Integer = (bounds.Width - ((2 * margin.Width) + ((3 * size2.Width) / 2)))
                Dim actualTextSize As Size = Me.actualTextSize
                actualTextSize.Width = (actualTextSize.Width / Me.Text.Length)
                actualTextSize.Width = (actualTextSize.Width + If(((actualTextSize.Width Mod Me.Text.Length) > 0), 1, 0))
                actualTextSize.Width = (actualTextSize.Width * Math.Min(Me.Text.Length, 7))
                Dim empty As Size = Size.Empty
                empty.Width = Math.Min(num, Me.actualTextSize.Width)
                empty.Width = Math.Max(1, Math.Max(empty.Width, actualTextSize.Width))
                empty.Height = actualTextSize.Height
                Dim num2 As Integer = (Me.actualTextSize.Width / empty.Width)
                num2 = (num2 + If(((Me.actualTextSize.Width Mod empty.Width) > 0), 1, 0))
                num2 = Math.Min(num2, 1)
                empty.Height = (empty.Height * num2)
                rectangle2 = New Rectangle(bounds.Location, empty) { _
                    .X = (rectangle2.X + ((bounds.Width - (((3 * size2.Width) / 2) + empty.Width)) / 2)), _
                    .X = (rectangle2.X + ((3 * size2.Width) / 2)), _
                    .Y = (rectangle2.Y + (2 * margin.Height)) _
                }
                If (size2.Height > empty.Height) Then
                    rectangle2.Y = (rectangle2.Y + ((size2.Height - empty.Height) / 2))
                End If
                rectangle2.Size = empty
                Return rectangle2
            End Get
        End Property

        Protected Overridable ReadOnly Property TitleHeight As Integer
            Get
                Dim margin As Size = WorkflowTheme.CurrentTheme.AmbientTheme.Margin
                Dim expandButtonRectangle As Rectangle = Me.ExpandButtonRectangle
                Dim textRectangle As Rectangle = Me.TextRectangle
                Dim imageRectangle As Rectangle = Me.ImageRectangle
                Dim num As Integer = 0
                If Not textRectangle.Size.IsEmpty Then
                    num = (Math.Max(expandButtonRectangle.Height, textRectangle.Height) + imageRectangle.Height)
                Else
                    num = Math.Max(expandButtonRectangle.Height, imageRectangle.Height)
                End If
                If ((Not expandButtonRectangle.Size.IsEmpty OrElse Not textRectangle.Size.IsEmpty) OrElse Not imageRectangle.Size.IsEmpty) Then
                    num = (num + (If(Me.Expanded, 2, 3) * margin.Height))
                End If
                If (Not imageRectangle.Size.IsEmpty AndAlso Not textRectangle.Size.IsEmpty) Then
                    num = (num + margin.Height)
                End If
                Return num
            End Get
        End Property


        ' Fields
        Private accessibilityObject As CompositeDesignerAccessibleObject
        Private actualTextSize As Size = Size.Empty
        Private Const CF_DESIGNER As String = "CF_WINOEDESIGNERCOMPONENTS"
        Private Const CF_DESIGNERSTATE As String = "CF_WINOEDESIGNERCOMPONENTSSTATE"
        Private containedActivityDesigners As List([Of] ActivityDesigner)
        Private expanded As Boolean = True
        Private Const MaximumCharsPerLine As Integer = 8
        Private Const MaximumTextLines As Integer = 1
    End Class
End Namespace

